/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.mailbox.ContactConstants;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_42828
/*     */   extends UpgradeOp
/*     */ {
/*     */   void doUpgrade()
/*     */     throws ServiceException
/*     */   {
/*  35 */     upgrade_zimbraGalLdapAttrMap();
/*  36 */     upgrade_zimbraContactHiddenAttributes();
/*     */   }
/*     */   
/*     */   void upgrade_zimbraGalLdapAttrMap() throws ServiceException
/*     */   {
/*  41 */     String attrName = "zimbraGalLdapAttrMap";
/*     */     
/*  43 */     Config config = this.prov.getConfig();
/*     */     
/*  45 */     this.printer.println();
/*  46 */     this.printer.println("Checking " + config.getLabel() + " for " + attrName);
/*     */     
/*  48 */     String oldCalResType = "zimbraCalResType=zimbraCalResType";
/*  49 */     String newCalResType = "zimbraCalResType,msExchResourceSearchProperties=zimbraCalResType";
/*     */     
/*  51 */     String oldCalResLocationDisplayName = "zimbraCalResLocationDisplayName=zimbraCalResLocationDisplayName";
/*  52 */     String newCalResLocationDisplayName = "zimbraCalResLocationDisplayName,displayName=zimbraCalResLocationDisplayName";
/*     */     
/*  54 */     String oldMailForwardingAddress = "zimbraMailForwardingAddress=zimbraMailForwardingAddress";
/*  55 */     String newMailForwardingAddress = "zimbraMailForwardingAddress=member";
/*     */     
/*  57 */     String zimbraCalResBuilding = "zimbraCalResBuilding=zimbraCalResBuilding";
/*  58 */     String zimbraCalResCapacity = "zimbraCalResCapacity,msExchResourceCapacity=zimbraCalResCapacity";
/*  59 */     String zimbraCalResFloor = "zimbraCalResFloor=zimbraCalResFloor";
/*  60 */     String zimbraCalResSite = "zimbraCalResSite=zimbraCalResSite";
/*  61 */     String zimbraCalResContactEmail = "zimbraCalResContactEmail=zimbraCalResContactEmail";
/*  62 */     String zimbraAccountCalendarUserType = "msExchResourceSearchProperties=zimbraAccountCalendarUserType";
/*     */     
/*  64 */     String[] curValues = config.getMultiAttr(attrName);
/*     */     
/*  66 */     Map<String, Object> attrs = new HashMap();
/*  67 */     for (String curValue : curValues) {
/*  68 */       replaceIfNeeded(attrs, attrName, curValue, oldCalResType, newCalResType);
/*  69 */       replaceIfNeeded(attrs, attrName, curValue, oldCalResLocationDisplayName, newCalResLocationDisplayName);
/*  70 */       replaceIfNeeded(attrs, attrName, curValue, oldMailForwardingAddress, newMailForwardingAddress);
/*     */     }
/*     */     
/*  73 */     addValue(attrs, attrName, zimbraCalResBuilding);
/*  74 */     addValue(attrs, attrName, zimbraCalResCapacity);
/*  75 */     addValue(attrs, attrName, zimbraCalResFloor);
/*  76 */     addValue(attrs, attrName, zimbraCalResSite);
/*  77 */     addValue(attrs, attrName, zimbraCalResContactEmail);
/*  78 */     addValue(attrs, attrName, zimbraAccountCalendarUserType);
/*     */     
/*  80 */     if (attrs.size() > 0) {
/*  81 */       this.printer.println("Modifying " + attrName + " on " + config.getLabel());
/*  82 */       this.prov.modifyAttrs(config, attrs);
/*     */     }
/*     */   }
/*     */   
/*     */   private void upgrade_zimbraContactHiddenAttributes(Entry entry, String entryName) throws ServiceException
/*     */   {
/*  88 */     String attrName = "zimbraContactHiddenAttributes";
/*     */     
/*  90 */     this.printer.println();
/*  91 */     this.printer.println("Checking " + entryName + " for " + attrName);
/*     */     
/*  93 */     String curValue = entry.getAttr(attrName);
/*     */     
/*     */ 
/*     */ 
/*  97 */     String newHiddenAttrs = "";
/*  98 */     if (curValue != null) {
/*  99 */       String[] curHiddenAttrs = curValue.split(",");
/* 100 */       boolean seenMember = false;
/* 101 */       boolean first = true;
/* 102 */       for (String hiddenAttr : curHiddenAttrs) {
/* 103 */         if ((!"zimbraCalResType".equalsIgnoreCase(hiddenAttr)) && (!"zimbraCalResLocationDisplayName".equalsIgnoreCase(hiddenAttr)) && (!"zimbraCalResCapacity".equalsIgnoreCase(hiddenAttr)) && (!"zimbraCalResContactEmail".equalsIgnoreCase(hiddenAttr)) && (!"zimbraAccountCalendarUserType".equalsIgnoreCase(hiddenAttr)))
/*     */         {
/*     */ 
/*     */ 
/*     */ 
/* 108 */           if (!first) {
/* 109 */             newHiddenAttrs = newHiddenAttrs + ",";
/*     */           } else
/* 111 */             first = false;
/* 112 */           newHiddenAttrs = newHiddenAttrs + hiddenAttr;
/*     */         }
/*     */         
/* 115 */         if (ContactConstants.A_member.equalsIgnoreCase(hiddenAttr)) {
/* 116 */           seenMember = true;
/*     */         }
/*     */       }
/*     */       
/*     */ 
/* 121 */       if (!seenMember) {
/* 122 */         if (!first)
/* 123 */           newHiddenAttrs = newHiddenAttrs + ",";
/* 124 */         newHiddenAttrs = newHiddenAttrs + ContactConstants.A_member;
/*     */       }
/*     */     }
/* 127 */     if (newHiddenAttrs.length() == 0) {
/* 128 */       newHiddenAttrs = "dn,zimbraAccountCalendarUserType,vcardUID,vcardURL,vcardXProps" + ContactConstants.A_member;
/*     */     }
/* 130 */     Map<String, Object> attrs = new HashMap();
/* 131 */     attrs.put("zimbraContactHiddenAttributes", newHiddenAttrs);
/*     */     
/* 133 */     if (attrs.size() > 0) {
/* 134 */       this.printer.println("Modifying " + attrName + " on " + entryName + " from " + curValue + " to " + newHiddenAttrs);
/* 135 */       this.prov.modifyAttrs(entry, attrs);
/*     */     }
/*     */   }
/*     */   
/*     */   private void upgrade_zimbraContactHiddenAttributes() throws ServiceException {
/* 140 */     Config config = this.prov.getConfig();
/* 141 */     upgrade_zimbraContactHiddenAttributes(config, config.getLabel());
/*     */     
/* 143 */     List<Server> servers = this.prov.getAllServers();
/*     */     
/* 145 */     for (Server server : servers) {
/* 146 */       upgrade_zimbraContactHiddenAttributes(server, "server " + server.getLabel());
/*     */     }
/*     */   }
/*     */   
/*     */   private void replaceIfNeeded(Map<String, Object> attrs, String attrName, String curValue, String oldValue, String newValue) {
/* 151 */     if (curValue.equalsIgnoreCase(oldValue)) {
/* 152 */       this.printer.println("    removing value: " + oldValue);
/* 153 */       this.printer.println("    adding value: " + newValue);
/*     */       
/* 155 */       StringUtil.addToMultiMap(attrs, "-" + attrName, oldValue);
/* 156 */       StringUtil.addToMultiMap(attrs, "+" + attrName, newValue);
/*     */     }
/*     */   }
/*     */   
/*     */   private void addValue(Map<String, Object> attrs, String attrName, String value) {
/* 161 */     this.printer.println("    adding value: " + value);
/* 162 */     StringUtil.addToMultiMap(attrs, "+" + attrName, value);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_42828.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */